<?php require_once('Connections/locamedicadmin.php'); ?>

<?php include('userValidation.php'); ?>

<?php require_once('functions.php'); ?>

<?php

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_commandes = 20;
$pageNum_commandes = 0;
if (isset($_GET['pageNum_commandes'])) {
  $pageNum_commandes = $_GET['pageNum_commandes'];
}
$startRow_commandes = $pageNum_commandes * $maxRows_commandes;

mysql_select_db($database_locamedicadmin, $locamedicadmin);
$query_commandes = "select co.codigo, co.medipoints, co.date_commande, co.state, cl.name 
from csre_commande co left join csre_client cl on cl.client_id = co.client_id where co.state = 0";

$query_limit_commandes = sprintf("%s LIMIT %d, %d", $query_commandes, $startRow_commandes, $maxRows_commandes);
$commandes = mysql_query($query_limit_commandes, $locamedicadmin) or die(mysql_error());
$row_commandes = mysql_fetch_assoc($commandes);

if (isset($_GET['totalRows_commandes'])) {
  $totalRows_commandes = $_GET['totalRows_commandes'];
} else {
  $all_commandes = mysql_query($query_commandes);
  $totalRows_commandes = mysql_num_rows($all_commandes);
}
$totalPages_commandes = ceil($totalRows_commandes/$maxRows_commandes)-1;

$queryString_commandes = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_commandes") == false && 
        stristr($param, "totalRows_commandes") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_commandes = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_commandes = sprintf("&totalRows_commandes=%d%s", $totalRows_commandes, $queryString_commandes);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Locamedic CSRE Admin</title>
<link href="locamedicadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="page">

	<?php include('sidebar.php'); ?>
	
	<!-- end sidebar -->
	<div id="content">
		<div align="center"><img src="images/page_image_5.jpg" alt="" /></div>
	  <div class="boxed">
		<h1 class="title2">Commandes List</h1>
		<br />
		
		<?php if ($totalRows_commandes > 0) { ?>
		<table cellpadding="5" cellspacing="0">
		  <thead>
		    <td>Commande Code</td>
			<td>Date</td>
			<td>Client</td>
			<td>Medipoints</td>
			<td width="5%"></td>
			<td width="5%"></td>
		 </thead>
		  <?php do { ?>
			<tr>
			  <td><?php echo $row_commandes['codigo']; ?></td>
			  <td><?php echo $row_commandes['date_commande']; ?></td>
			  <td><?php echo $row_commandes['name']; ?></td>
			  <td><?php echo $row_commandes['medipoints']; ?></td>
			  <td>
			  	<a href="commande_detail.php?codigo=<?php echo $row_commandes['codigo'];?>">
					<img src="images/1307912835_old-edit-find.png" alt="" />
				</a>
			  </td>			  			  
  			  <td>
			  	<a href="commande_close.php?codigo=<?php echo $row_commandes['codigo'];?>" onclick="return confirm('Etes-vous sur de vouloir fermer la commande?');">
					<img src="images/1311143533_button_cancel.png" alt="" />
				</a>
			  </td>			  			  

			</tr>
			<?php } while ($row_commandes = mysql_fetch_assoc($commandes)); ?>
		</table>
		<table>
			<tr>
				<td align="center">
					Rows <?php echo ($startRow_commandes + 1) ?> to <?php echo min($startRow_commandes + $maxRows_commandes, $totalRows_commandes) ?> of <?php echo $totalRows_commandes ?>
				</td>
			</tr>
		</table>
		       

		
		<table border="0" width="50%" align="center">
          <tr>
            <td width="23%" align="center"><?php if ($pageNum_commandes > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_commandes=%d%s", $currentPage, 0, $queryString_commandes); ?>"><img src="images/resultset_first.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="31%" align="center"><?php if ($pageNum_commandes > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_commandes=%d%s", $currentPage, max(0, $pageNum_commandes - 1), $queryString_commandes); ?>"><img src="images/resultset_previous.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_commandes < $totalPages_commandes) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_commandes=%d%s", $currentPage, min($totalPages_commandes, $pageNum_commandes + 1), $queryString_commandes); ?>"><img src="images/resultset_next.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_commandes < $totalPages_commandes) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_commandes=%d%s", $currentPage, $totalPages_commandes, $queryString_commandes); ?>"><img src="images/resultset_last.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
          </tr>
        </table>
		<?php } else { ?>
		<table>
			<tr>
				<td>No commandes found</td>
			</tr>
		</table>
		<?php } ?>
	  </div>
  </div>
	<!-- end content -->
	<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->

<?php include('footer.php'); ?>

</body>
</html>
<?php
mysql_free_result($commandes);
?>